<?php
namespace app\admin\controller;
use app\admin\model\IndexTableModel;
use app\admin\model\JoinTableModel;
use app\admin\controller\Cloudaccountwithdraw;
use think\Db;
use think\Request;
use app\common\model\User;
use app\common\model\UserLevel;
use app\common\validate\UserValidate;

require_once (__DIR__.'/../../../vendor/ReidsLock.class.php');
class FawithdrawController extends Controller
{

    /**
     * 提现审核列表
     * User:@hang
     */
    public function index(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['me_uid']) && !empty($param['me_uid'])) {
            $whehe[] = ['b.me_uid','=',$param['me_uid']];
        }
        if (isset($param['me_phone']) && !empty($param['me_phone'])) {
            $whehe[] = ['b.me_phone|b.me_nick_name','like',"%{$param['me_phone']}%"];
        }
        if (isset($param['me_sex']) && !empty($param['me_sex'])) {
            $whehe[] = ['b.me_sex','=',$param['me_sex']];
        }
        if (isset($param['order_number']) && !empty($param['order_number'])) {
            $whehe[] = ['a.order_number','like',"%{$param['order_number']}%"];
        }
        if (isset($param['status']) && $param['status'] != '') {
            $whehe[] = ['a.status','=',$param['status']];
        }
        if (isset($param['sk_type']) && !empty($param['sk_type'])) {
            $whehe[] = ['a.sk_type','=',$param['sk_type']];
        }
        if (isset($param['is_pending']) && $param['is_pending'] != '') {
            $whehe[] = ['a.is_pending','=',$param['is_pending']];
        }
        if (isset($param['is_pass_withdrawal']) && $param['is_pass_withdrawal'] != '') {
            $whehe[] = ['b.is_pass_withdrawal','=',$param['is_pass_withdrawal']];
        }
        $whehetime = '';
        if (isset($param['add_time']) && !empty($param['add_time'])) {
            $time_arr = explode(' - ', $param['add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1].'23:59:59');
            $whehetime = "a.add_time >= $start_time AND a.add_time <= $end_time";
        }
        if (isset($param['f_member_id']) && !empty($param['f_member_id'])) {
            $whehe[] = ['a.f_id','=',$param['f_member_id']];
        }

        $data = Db::table('fa_zwithdrawal_order')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->join("fa_member c",'a.f_id = c.member_id','LEFT')
            ->join("fa_member_fund d",'a.member_id = d.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.*,b.me_uid,b.me_phone,b.me_nick_name,b.me_sex,b.me_realname,b.me_realidcard,b.me_status,c.member_id as f_member_id,c.me_uid as f_me_uid,c.me_nick_name as f_me_nick_name,d.stamp_money,d.no_stamp_money,b.is_pass_withdrawal')
            ->order('a.add_time desc')
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $start_time = strtotime(date('Y-m-d',time()));
        $end_time = $start_time + 86399;
        $last_start_time = $start_time - 86400;
        $last_end_time = $end_time - 86400;

        $adminid = $this->uid;
        $data->each(function ($v, $k)use($adminid,$last_start_time,$last_end_time) {
            $videoInfo = Db::table('fa_short_video')->where("member_id = '{$v['member_id']}' and status = 1 and is_show = 1 and is_delete = 1")->field('id as video_id,short_content,add_time as video_add_time')->order('add_time desc,id desc')->find();
            $v['video_add_time'] = !empty($videoInfo)?date('Y-m-d H:i:s',$videoInfo['video_add_time']):'未发';

            switch($v['is_pass_withdrawal']){
                case '0': $v['is_pass_withdrawal_word'] = '未开启';break;
                case '1': $v['is_pass_withdrawal_word'] = '已开启';break;
            }

            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }
            $v['tr_color'] = '0';//无颜色
            if($v['add_time'] >= $last_start_time && $v['add_time'] <= $last_end_time){
                $v['tr_color'] = '1';
            }
            if($v['me_sex'] == 1){
                $v['tr_color'] = '2';
            }
            if(empty($v['f_member_id'])){
                $v['tr_color'] = '3';
            }

            switch($v['is_pending']){
                case '0': $v['is_pending_word'] = '未设置';break;
                case '1': $v['is_pending_word'] = '已设置';break;
            }
            switch($v['status']){
                case '0': $v['status_word'] = '待审核';break;
                case '1':
                    $v['status_word'] = '同意提现';
                    if($v['operation_user_id'] == -99){
                        $v['status_word'] .= '(免审核)';
                    }
                break;
                case '2': $v['status_word'] = '拒绝提现';break;
            }
            switch($v['me_sex']){
                case '0': $v['me_sex_word'] = '未设置';break;
                case '1': $v['me_sex_word'] = '男';break;
                case '2': $v['me_sex_word'] = '女';break;
            }
            switch($v['me_status']){
                case '1': $v['me_status_word'] = '';break;
                case '2': $v['me_status_word'] = '（已封禁）';break;
            }
            if($v['sk_type'] == 1){
                $v['sk_type_word'] = '微信';
                $v['sk_type_info'] = '用户微信';
            }
            if($v['sk_type'] == 2){
                $v['sk_type_word'] = '支付宝';
                $v['sk_type_info'] = $v['alipay_name'].' '.$v['alipay_number'];
            }
            if($v['sk_type'] == 3){
                $v['sk_type_word'] = '银行卡';
                $v['sk_type_info'] = $v['bank_phone'].' '.$v['bank_name'].' '.$v['bank_number'].' '.$v['bank_kh'];
            }
            if(!empty($v['content'])){
                $v['content_sl'] = cutStr($v['content'],5);
            }else{
                $v['content_sl'] = '未审核';
            }
            $v['add_time'] = date('Y-m-d H:i:s',$v['add_time']);
            $v['operation_time'] = !empty($v['operation_time'])?date('Y-m-d H:i:s',$v['operation_time']):'未审核';
            $v['after_money_word'] = $v['after_money'] == -1?'-':$v['after_money'];
            return $v;
        });

        //提现待审核总金额
        $dsh_money = Db::table('fa_zwithdrawal_order')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("`status` = 0")
            ->where($whehe)
            ->where($whehetime)
            ->sum('a.actual_withdrawal');
        $yzhyc_money = delete0(bcmul($dsh_money,1.065,4));
        //提现通过总金额
        $tg_money = Db::table('fa_zwithdrawal_order')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("`status` = 1")
            ->where($whehe)
            ->where($whehetime)
            ->sum('a.actual_withdrawal');
        //提现拒绝总金额
        $jj_money = Db::table('fa_zwithdrawal_order')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where("`status` = 2")
            ->where($whehe)
            ->where($whehetime)
            ->sum('a.actual_withdrawal');

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
            'dsh_money' => $dsh_money,
            'tg_money' => $tg_money,
            'jj_money' => $jj_money,
            'yzhyc_money' => $yzhyc_money,
        ]);
        return $this->fetch();
    }



    /**
     * 通过提现 页面
     * User:@hang
     */
    public function passwithdraw($id)
    {
        //查询提现详情
        $IndexTableModel = New IndexTableModel();
        $info = $IndexTableModel->getFind('fa_zwithdrawal_order',"`id` = '{$id}'",'*');
        if(empty($info)){
            return admin_error('提现信息未查询到',URL_CLOSE_REFRESH);
        }
        $is_show = '1';
        if($info['status'] != 0){
            $is_show = '这笔提现已经处理过，请关闭弹框，刷新页面再看！';
        }
        switch($info['sk_type']){
            case '1': $info['sk_type_word'] = '微信';break;
            case '2': $info['sk_type_word'] = '支付宝';break;
            case '3': $info['sk_type_word'] = '银行卡';break;
        }
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$info['member_id']}'",'member_id,me_uid,me_phone,me_nick_name,me_sex,me_realname,me_realidcard');
        switch($memberInfo['me_sex']){
            case '0': $memberInfo['me_sex_word'] = '未设置';break;
            case '1': $memberInfo['me_sex_word'] = '男';break;
            case '2': $memberInfo['me_sex_word'] = '女';break;
        }
        $info['add_time'] = date('Y-m-d H:i:s',$info['add_time']);

        $fee_list = ['7'=>'7%','6.5'=>'6.5%'];

        $this->assign([
            'data' => $id,
            'info' => $info,
            'memberinfo' => $memberInfo,
            'ql_fee' => $info['fee_bl'],
            'ql_fee_word' => $info['fee_bl'].'（系统默认）',
            'fee_list' => $fee_list,
            'is_show' => $is_show,
        ]);
        return $this->fetch();
    }

    /**
     * 确认 通过提现
     * User:@hang
     */
    public function actionpasswithdraw()
    {
        $fee_zx_bl = input('fee_zx_bl');//执行的提现手续费比例
        $id = input('id');
        $content = replaceSpecialChar(input('content'));
        if(empty($content)){
            $content = '已通过用户的提现申请';
        }
        $IndexTableModel = New IndexTableModel();
        $tinfo = $IndexTableModel->getFind('fa_zwithdrawal_order',"`id` = '{$id}'",'*');
        if(empty($tinfo)){
            return admin_error('提现信息未查询到',URL_CLOSE_REFRESH);
        }
        if($tinfo['sk_type'] == 3){
            return admin_error('银行卡提现不可通过老版本通过（云账户不支持）',URL_CLOSE_REFRESH);
        }
        if($tinfo['status'] != 0){
            return admin_error('提现申请已经处理过，无需再次处理',URL_CLOSE_REFRESH);
        }
        if($tinfo['is_pending'] == 1){
            return admin_error('已经设置待定，不可审核此提现',URL_CLOSE_REFRESH);
        }
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:actionpasswithdraw'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试',URL_CLOSE_REFRESH);
        }
        $ctime = time();
        Db::startTrans();
        $tmemberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$tinfo['member_id']}'",'member_id,me_uid,me_phone,me_nick_name,me_sex,me_realname,me_realidcard,me_is_real,me_yzh,me_status');
        if(empty($tmemberInfo)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('您的用户信息未查询到',URL_CLOSE_REFRESH);
        }
        if($tmemberInfo['me_status'] != 1){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户已经被封禁，不可通过提现',URL_CLOSE_REFRESH);
        }

        //=============云账户提现==================
        if($tmemberInfo['me_is_real'] != 1){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户未通过实名认证，不可通过提现',URL_CLOSE_REFRESH);
        }
        if($tmemberInfo['me_yzh'] != 1){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户未签约云账户，不可通过提现',URL_CLOSE_REFRESH);
        }
        if(empty($tmemberInfo['me_realname']) || empty($tmemberInfo['me_realidcard'])){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户姓名或身份证号未查询到，不可通过提现',URL_CLOSE_REFRESH);
        }
        if(empty($tmemberInfo['me_phone'])){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户手机号未查询到，不可通过提现',URL_CLOSE_REFRESH);
        }

        //计算真实到账金额
        if($tinfo['fee_bl'] == $fee_zx_bl){
            //无更改
            $fee_bl = $fee_zx_bl;//手续费比例
            $fee_withdrawal = $tinfo['fee_withdrawal'];//手续费油票数
            $payMoney = delete0(bcadd($tinfo['actual_withdrawal'],0,2));//到账金额
        }else{
            //有更改
            $fee_bl = $fee_zx_bl;//手续费比例
            $withdrawfee = bcdiv($fee_bl,100,4);
            $fee_withdrawal = delete0(bcmul($withdrawfee,$tinfo['total_withdrawal'],2));//手续费油票数
            //计算真实到账金额
            $Common = New Common();
            $stampmoney = $Common->getConfigValue('stampmoney');//1油票价值人民币
            $actual_withdrawal = delete0(bcmul(bcsub($tinfo['total_withdrawal'],$fee_withdrawal,2),$stampmoney,2));
            $payMoney = delete0(bcadd($actual_withdrawal,0,2));//到账金额
        }

//        var_dump($fee_bl);
//        var_dump($fee_withdrawal);
//        var_dump($payMoney);
//        die;

        $Cloudaccountwithdraw = New Cloudaccountwithdraw();
        if($tinfo['sk_type']==1){
            if(empty($tinfo['wechat_openid'])){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('用户微信收款信息未查询到，不可通过提现',URL_CLOSE_REFRESH);
            }
            $yzhRes = $Cloudaccountwithdraw->wxyunzhanghu($tinfo['order_number'],$tmemberInfo['me_realname'],strtoupper($tmemberInfo['me_realidcard']),$tinfo['wechat_openid'],$tmemberInfo['me_phone'],$payMoney,getAppUrl().'api/Cloudaccountwithdraw/yzhcallback');
        }else{
            if(empty($tinfo['alipay_number'])){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('用户支付宝收款信息未查询到，不可通过提现',URL_CLOSE_REFRESH);
            }
            $yzhRes = $Cloudaccountwithdraw->zfbyunzhanghu($tinfo['order_number'],$tmemberInfo['me_realname'],strtoupper($tmemberInfo['me_realidcard']),$tinfo['alipay_number'],$tmemberInfo['me_phone'],$payMoney,getAppUrl().'api/Cloudaccountwithdraw/yzhcallback');
        }
        if($yzhRes['code'] != 200){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('云账户打款失败，'.$yzhRes['msg'],URL_CLOSE_REFRESH);
        }
        //=======================================

        //修改提现订单状态
        $res = $IndexTableModel->editInfo('fa_zwithdrawal_order',"`id` = '{$id}'",array('status'=>1,'operation_user_id'=>$this->uid,'operation_time'=>$ctime,'content'=>$content,'fee_bl'=>$fee_bl,'fee_withdrawal'=>$fee_withdrawal,'actual_withdrawal'=>$payMoney,'is_pending'=>0));
        if(empty($res)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('修改提现订单状态失败',URL_CLOSE_REFRESH);
        }
        //增加财务日志
        $member_money = $IndexTableModel->getFind('fa_member_fund',"`member_id` = '{$tinfo['member_id']}'",'member_id,stamp_money');
        $member_money_stamp_money = !empty($member_money)?$member_money['stamp_money']:'0.00';
        $financeRes = $IndexTableModel->addInfo('fa_finance',array('member_id'=>$tinfo['member_id'],'d_member_id'=>0,'g_table'=>'fa_zwithdrawal_order','g_id'=>$id,'type'=>15,'money_type'=>2,'status'=>2,'money'=>$tinfo['total_withdrawal'],'member_money'=>$member_money_stamp_money,'content'=>'您于【'.date('Y-m-d H:i:s',$tinfo['add_time']).'】提现已经通过'.'（流水号：'.$tinfo['order_number'].'）','add_time'=>$ctime,'chat_type'=>0));
        if(empty($financeRes)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('增加通过提现财务日志',URL_CLOSE_REFRESH);
        }
        //添加服务通知
        switch($tinfo['sk_type']){
            case '1': $sk_type_word = '微信';break;
            case '2': $sk_type_word = '支付宝';break;
            case '3': $sk_type_word = '银行卡';break;
        }
        $newsRes = $IndexTableModel->addInfo('fa_news_service',array('type'=>3,'member_id'=>0,'j_member_id'=>$tinfo['member_id'],'g_table'=>'fa_zwithdrawal_order','g_id'=>$id,'content'=>'恭喜，您于【'.date('Y-m-d H:i:s',$tinfo['add_time']).' 的'.$sk_type_word.'提现申请已经通过，提现油票数'.$tinfo['total_withdrawal'].'，实际到账金额'.$payMoney.'元】，通过时间：'.date('Y-m-d H:i:s',$ctime).'，通过理由：【'.$content.'】'.'，您可以到对应账户查看到账情况。'.'（流水号：'.$tinfo['order_number'].'）','is_read'=>0,'add_time'=>$ctime));
        if(empty($newsRes)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('添加服务通知失败',URL_CLOSE_REFRESH);
        }
        Db::commit();
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('通过提现成功',URL_CLOSE_REFRESH);
    }


    /**
     * 拒绝提现 页面
     * User:@hang
     */
    public function refusewithdraw($id)
    {
        //查询提现详情
        $IndexTableModel = New IndexTableModel();
        $info = $IndexTableModel->getFind('fa_zwithdrawal_order',"`id` = '{$id}'",'*');
        $is_show = '1';
        if($info['status'] != 0){
            $is_show = '这笔提现已经处理过，请关闭弹框，刷新页面再看！';
        }
        switch($info['sk_type']){
            case '1': $info['sk_type_word'] = '微信';break;
            case '2': $info['sk_type_word'] = '支付宝';break;
            case '3': $info['sk_type_word'] = '银行卡';break;
        }
        $info['add_time'] = date('Y-m-d H:i:s',$info['add_time']);
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$info['member_id']}'",'member_id,me_uid,me_phone,me_nick_name,me_sex,me_realname,me_realidcard');
        switch($memberInfo['me_sex']){
            case '0': $memberInfo['me_sex_word'] = '未设置';break;
            case '1': $memberInfo['me_sex_word'] = '男';break;
            case '2': $memberInfo['me_sex_word'] = '女';break;
        }
        $this->assign([
            'data' => $id,
            'info' => $info,
            'memberinfo' => $memberInfo,
            'is_show' => $is_show
        ]);
        return $this->fetch();
    }



    /**
     * 确认 拒绝提现
     * User:@hang
     */
    public function actionrefusewithdraw()
    {
        $id = input('id');
        $content = replaceSpecialChar(input('content'));
        if(empty($content)){
            $content = '您的提现已拒绝，请联系客服';
        }
        $IndexTableModel = New IndexTableModel();
        $tinfo = $IndexTableModel->getFind('fa_zwithdrawal_order',"`id` = '{$id}'",'*');
        if(empty($tinfo)){
            return admin_error('提现信息未查询到',URL_CLOSE_REFRESH);
        }
        if($tinfo['status'] != 0){
            return admin_error('提现申请已经处理过，无需再次处理',URL_CLOSE_REFRESH);
        }
        if($tinfo['is_pending'] == 1){
            return admin_error('已经设置待定，不可审核此提现',URL_CLOSE_REFRESH);
        }
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:actionrefusewithdraw'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试',URL_CLOSE_REFRESH);
        }
        $ctime = time();
        Db::startTrans();
        $tmemberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$tinfo['member_id']}'",'member_id,me_uid,me_phone,me_nick_name,me_sex,me_realname,me_realidcard,me_is_real,me_yzh');
        if(empty($tmemberInfo)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('您的用户信息未查询到',URL_CLOSE_REFRESH);
        }
        //修改提现订单状态
        $res = $IndexTableModel->editInfo('fa_zwithdrawal_order',"`id` = '{$id}'",array('status'=>2,'operation_user_id'=>$this->uid,'operation_time'=>$ctime,'content'=>$content,'is_pending'=>0));
        if(empty($res)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('修改提现订单状态失败',URL_CLOSE_REFRESH);
        }
        $total_withdrawal = $tinfo['total_withdrawal'];//返还用户油票数
        $Common = New Common();
        //增加用户油票数
        $yp_res = $Common->incStampMoney($tinfo['member_id'],1,$total_withdrawal);
        if($yp_res != 200){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('加用户可提现油票数失败',URL_CLOSE_REFRESH);
        }
        //增加用户财务日志
        $finRes = $Common->setFinance($tinfo['member_id'],0,'fa_zwithdrawal_order',$id,14,2,1,$total_withdrawal,'您于【'.date('Y-m-d H:i:s',$tinfo['add_time']).'】提现已被拒绝'.'（流水号：'.$tinfo['order_number'].'）',0);
        if($finRes['code'] != 200){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('增加用户财务日志失败',URL_CLOSE_REFRESH);
        }
        //添加服务通知
        switch($tinfo['sk_type']){
            case '1': $sk_type_word = '微信';break;
            case '2': $sk_type_word = '支付宝';break;
            case '3': $sk_type_word = '银行卡';break;
        }
        $newsRes = $IndexTableModel->addInfo('fa_news_service',array('type'=>4,'member_id'=>0,'j_member_id'=>$tinfo['member_id'],'g_table'=>'fa_zwithdrawal_order','g_id'=>$id,'content'=>'抱歉，您于【'.date('Y-m-d H:i:s',$tinfo['add_time']).' 的'.$sk_type_word.'提现申请被拒绝，提现油票数'.$tinfo['total_withdrawal'].'】，拒绝时间：'.date('Y-m-d H:i:s',$ctime).'，拒绝理由【'.$content.'】，油票已返还到原账户，您可以到钱包中查看。'.'（流水号：'.$tinfo['order_number'].'）','is_read'=>0,'add_time'=>$ctime));
        if(empty($newsRes)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('添加服务通知失败',URL_CLOSE_REFRESH);
        }
        Db::commit();
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('拒绝提现成功',URL_CLOSE_REFRESH);
    }



    //设置/取消 待定标签
    public function setpending($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:setpending'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_zwithdrawal_order',"`id` = '{$id}'",array('is_pending'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }


    //设置/取消 提现免审核
    public function setpassmsh($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:setpassmsh'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('is_pass_withdrawal'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }








    /**
     * 生成excel表格
     * User:@hang
     */
    public function setexcel($fileName,$data){
        //引用phpexcel
        require_once(__DIR__ . '/../../../vendor/PHPExcel/PHPExcel.php');
        require_once(__DIR__ . '/../../../vendor/PHPExcel/PHPExcel/IOFactory.php');
        // import('PHPExcel.PHPExcel',EXTEND_PATH,'.php');
        // import('PHPExcel.PHPExcel.IOFactory',EXTEND_PATH,'.php');
        $excel = new \PHPExcel();
        $name = $fileName;
        //针对中文名转码
        iconv('UTF-8', 'gb2312', $name);
        //表头,名称可自定义
        $header = [    //表头
            '筛选时间',
            '用户UID号',
            '昵称',
            '性别',
            '会员绑定人数',
            '扫码绑定人数',
            '邀请总人数',
            '会员绑定下级充值金额（筛选日）',
            '扫码绑定下级充值金额（筛选日）',
            '会员绑定下级充值收益（筛选日）',
            '扫码绑定下级充值收益（筛选日）',
            '文字收益（筛选日）',
            '音频收益（筛选日）',
            '视频收益（筛选日）',
            '私聊礼物收益（筛选日）',
            '聊天相关收益（筛选日）',
            '总收益（筛选日）',
            '累计总收益',
            '给上级充值收益（筛选日）',
            '给上级其它收益（筛选日）',
            '给上级累计总收益（筛选日）',
            '累计给上级总收益',
            '此女生免费文字收益（筛选日）',
            '此女生免费文字总收益',
            '此女生体验卷收益（筛选日）',
            '此女生体验卷总收益',
            '特殊礼物收益（筛选日）',
            '特殊礼物总收益',
        ];
        $excel->setActiveSheetIndex(0);
        //设置表名
        $excel->getActiveSheet()->setTitle($name);
        $excel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(18);
        //列坐标
        $letter = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB'];
        //生成表头
        for($i=0;$i<count($header);$i++){
            //设置表头值
            $excel->getActiveSheet()->setCellValue("$letter[$i]1",$header[$i]);
            //设置表头字体样式
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFont()->setName('宋体');
            //设置表头字体大小
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFont()->setSize(14);
            //设置表头字体是否加粗
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFont()->setBold(true);
            //设置表头文字水平居中
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getAlignment()->setWrapText(true);
            //设置文字上下居中
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
            if(in_array("$letter[$i]1",['H1','I1'])){
                //设置单元格背景色（蓝色）
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FFFFFFFF');
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FF0000FF');
            }elseif(in_array("$letter[$i]1",['S1','T1','U1','V1'])){
                //设置单元格背景色（红色）
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FFFFFFFF');
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FFFF0000');
            }elseif(in_array("$letter[$i]1",['A1','B1','C1','D1','E1','F1','G1'])){
                //设置单元格背景色（）
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FFFFFFFF');
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FF855E42');
            }elseif(in_array("$letter[$i]1",['W1','X1','Y1','Z1','AA1','AB1'])){
                //设置单元格背景色（）
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FFFFFFFF');
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FF4F4F2F');
            }else{
                //设置单元格背景色（绿色）
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FFFFFFFF');
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
                $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFill()->getStartColor()->setARGB('FF6DBA43');
            }
            //设置字体颜色（白色）
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getFont()->getColor()->setARGB('FFFFFFFF');
            $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
            $excel->getActiveSheet()->getStyle("$letter[$i]1")->getAlignment()->setWrapText(true);
        }
        $excel->getActiveSheet()->getColumnDimension("A")->setWidth(10);
        if(!empty($data)){
            //写入数据
            foreach($data as $k=>$v){
                //从第二行开始写入数据（第一行为表头）
                $excel->getActiveSheet()->setCellValue('A'.($k+2),$v['member_id']);
            }
        }

        //清理缓冲区，避免中文乱码
        ob_end_clean();
        //导出数据
        $obj=new \PHPExcel_Writer_Excel5($excel);//实例化 将对象放入表格中
        $download_url = './uploads/1excel/'.$name.'.xls'; //生成表格地址
        $obj->save($download_url);
        return $download_url;
    }



}
